package com.cn.hangyun.controller;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cn.hangyun.common.DateUtil;
import com.cn.hangyun.model.Rt_accelration_control;
import com.cn.hangyun.model.Rt_accelration_transducer;
import com.cn.hangyun.model.Rt_strain_control;
import com.cn.hangyun.model.Rt_strain_transducer;
import com.cn.hangyun.model.requestVO.AccelrationRequestBean;
import com.cn.hangyun.model.requestVO.StrainRequestBean;
import com.cn.hangyun.service.IModelService;


@Controller
@RequestMapping("/model")
public class ModelController {

	@Autowired
	private IModelService modelService;

	@RequestMapping("/accTrans")
	@ResponseBody
	public List<Rt_accelration_transducer> getAccTranas() {
		
		List<Rt_accelration_transducer> list = modelService.getAllAccTran();
		return list;
	}
	
	@RequestMapping("/strTrans")
	@ResponseBody
	public List<Rt_strain_transducer> getStrTranas(){
		
		List<Rt_strain_transducer> list = modelService.getAllStrTran();
		return list;
	}
	
	@RequestMapping("/accControl")
	@ResponseBody
	public Rt_accelration_control getAccControl(Date current) {
		
		Rt_accelration_control result = modelService.getLastAccelrationControl(current);
		return result;
	}
	
	@RequestMapping("/strControl")
	@ResponseBody
	public Rt_strain_control getStrControl(Date current) {
		
		Rt_strain_control result = modelService.getLastStrainControl(current);
		return result;
		
	}
	
	@RequestMapping(value="/accData", method=RequestMethod.POST)
	@ResponseBody
	public Map<String, List<String>> getAccData(String controlId, Date start, 
			int interval, @RequestParam(value = "trans[]") String[] trans) {
		
	     Date end = DateUtil.getEndTime(start, interval);
	     Map<String, List<String>> result = modelService.getAccData(controlId, start, end, trans);
	     return result;
	}
	
	@RequestMapping(value="/accDataMore", method=RequestMethod.POST)
	@ResponseBody
	public Map<String, List<String>> getAccDataMore(AccelrationRequestBean bean) {
	     
	     Map<String, List<String>> result = modelService.getAccDataMore(bean);
	     return result;
	}
	
	@RequestMapping(value="/strDataMore", method=RequestMethod.POST)
	@ResponseBody
	public Map<String, List<List<String>>> getStrDataMore(StrainRequestBean bean) {
		
	     Map<String, List<List<String>>> result = modelService.getStrDataMore(bean);
	     return result;
	}
	
}
